home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 16 / modem.fth < prev    next >
Text File  |  1985-11-19  |  3KB  |  102 lines

  1. \ Serial line handling.  Defines a vocabulary "modem" which contains:
  2. \
  3. \ m-key  ( -- char )    Get a character from the serial line
  4. \ m-key? ( -- flag )    True if a character is waiting
  5. \ m-emit ( char -- )    Output a character to the serial line
  6. \
  7. \   The following commands establish serial line parameters.
  8. \   They all have the stack diagram  ( -- )
  9. \
  10. \ 19200-baud  9600-baud  4800-baud  2400-baud  1200-baud  300-baud
  11. \ 0-stop-bits  1-stop-bit  1.5-stop-bits  2-stop-bits
  12. \ 8-bits  7-bits
  13. \ no-parity  odd-parity  even-parity
  14. \ no-flow-control  use-xon/xoff  use-rts/cts
  15. \
  16. \   Important:  They do not take effect until the set-line command is
  17. \   executed.
  18. \
  19. \ set-line    Make the established serial line parameters take effect
  20. \
  21. \ There are some (I presume) uninteresting parameters for which words
  22. \ are not defined (example - 2000-baud).  Comments in the code describe
  23. \ the appropriate magic numbers to use should you need to define them.
  24. \
  25. \ Warning: I have seen evidence that the act of setting the serial line
  26. \ parameters causes a single spurious 'ff' character to be output on the
  27. \ serial line.  I think this may be a bug in either the Atari BIOS or
  28. \ the serial line chip.
  29.  
  30. vocabulary modem
  31.  
  32. only forth also system also modem also definitions
  33.  
  34. alias m-key  c_auxin  ( -- char )
  35. alias m-key? c_auxis  ( -- flag )
  36. alias m-emit c_auxout ( char -- )
  37.  
  38. only forth also modem also definitions
  39. decimal
  40.  
  41. \ Translates baud rate to the appropriate magic number
  42.  
  43. variable baud-rate
  44. : baud: ( n -- ) ( Input stream: name )
  45.   create ,
  46.   does>  @ baud-rate !
  47. ;
  48. 0 baud: 19200-baud  1 baud: 9600-baud  2 baud: 4800-baud
  49. 4 baud: 2400-baud   7 baud: 1200-baud  9 baud:  300-baud
  50.  
  51. \ Other baud rates are available, though perhaps not useful
  52. \ Here is the full list:
  53. \  19200 ( 0 )   9600 ( 1 )   4800 ( 2 )   3600 ( 3 )   2400 ( 4 )
  54. \  2000  ( 5 )   1800 ( 6 )   1200 ( 7 )    600 ( 8 )    300 ( 9 )
  55.  
  56. variable #stop-bits
  57. : stop: ( n -- ) ( Input stream: name )
  58.   create , does> @ #stop-bits !
  59. ;
  60.  
  61.     0 stop: 0-stop-bits
  62. th 08 stop: 1-stop-bit
  63. th 10 stop: 1.5-stop-bits
  64. th 18 stop: 2-stop-bits
  65.  
  66. variable #data-bits
  67. : 8-bits ( -- )      0 #data-bits ! ;
  68. : 7-bits ( -- )  th 20 #data-bits ! ;
  69. \ 6-bits is th 40, 5-bits is th 60;  do people really use 6 or 5 bits?
  70.  
  71. variable parity
  72. : no-parity   ( -- )    0 parity ! ;
  73. : odd-parity  ( -- ) th 4 parity ! ;
  74. : even-parity ( -- ) th 6 parity ! ;
  75.  
  76. variable flow-control  0 flow-control !
  77.  
  78. : flow: ( n -- ) ( Input stream: name )
  79.   create , does> @ flow-control !
  80. ;
  81. 0 flow: no-flow-control
  82. 1 flow: use-xon/xoff
  83. 2 flow: use-rts/cts
  84.  
  85. wvariable ucr  th ffff ucr w!   \ USART control register image
  86. wvariable rsr  th ffff rsr w!   \ receive status register image
  87. wvariable tsr  th ffff tsr w!   \ transmit status register image
  88. wvariable scr  th ffff scr w!   \ sync character register image
  89.  
  90. td 15  xbios: rsconf { w.scr w.tsr w.rsr w.ucr w.flowctl w.speed -- }
  91.  
  92. : set-ucr ( -- )
  93.   th 80             \ This bit is the divide-by-16 bit
  94.   #stop-bits @ or   #data-bits @ or   parity @ or
  95.   ucr w!
  96. ;
  97. : set-line ( -- )
  98.   set-ucr
  99.   scr w@  tsr w@  rsr w@  ucr w@  flow-control @  baud-rate @
  100.     rsconf
  101. ;